package com.evildog.workspace.life.application.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.evildog.workspace.life.application.bo.AlbumTagBO;
import com.evildog.workspace.life.application.convert.AlbumTagConvert;
import com.evildog.workspace.life.application.dto.AlbumTagDTO;
import com.evildog.workspace.life.application.entity.AlbumTag;
import com.evildog.workspace.life.application.mapper.AlbumTagMapper;
import com.evildog.workspace.life.application.service.AlbumTagService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

@Service
public class AlbumTagServiceImpl extends ServiceImpl<AlbumTagMapper, AlbumTag> implements AlbumTagService {

    @Override
    public AlbumTagBO getDetailById(Long id) {
        AlbumTag albumTag = this.getById(id);
        Assert.notNull(albumTag, "albumTag is null!");
        return AlbumTagConvert.INSTANCE.convert(albumTag);
    }

    @Override
    public boolean save(AlbumTagDTO dto){
        AlbumTag newAlbumTag = AlbumTagConvert.INSTANCE.convert(dto);
        return save(newAlbumTag);
    }

    @Override
    public boolean updateById(Long id, AlbumTagDTO dto){
        AlbumTag oldAlbumTag = getById(id);
        Assert.notNull(oldAlbumTag, "albumTag is null!");
        AlbumTag newAlbumTag = AlbumTagConvert.INSTANCE.convert(dto);
        newAlbumTag.setId(id);
        return updateById(newAlbumTag);
    }
}
